<template>
  <work-template v-model="detailForm" @submitOn="submitOn" :is-cancel="false" :butShow="true">
    <div slot="form" class="container-div">
      <regulations v-model="detailForm" ref="refRegulations"/>
    </div>
  </work-template>
</template>

<script>
import * as apis from "@/api/warning"
import {queryConfig, saveOrUpdateConfig} from "@/api/warning";

export default {
  name: 'RegulationsWarning',
  components: {
    regulations: () => import('./regulations.vue')
  },
  computed: {},
  watch: {},
  data() {
    return {
      detailForm: {
        carViolationMessageConfig: {},
        carViolationMessageConfigList: []
      }
    };
  },
  created() {
    this.handleList()
  },
  mounted() {
  },
  methods: {
    async handleList() {
      try {
        let res = await apis?.queryConfig()
        this.detailForm = res
        if (this.detailForm.carViolationMessageConfig === null) {
          this.detailForm.carViolationMessageConfig = {}
        }
        if (this.detailForm.carViolationMessageConfigList === null) {
          this.detailForm.carViolationMessageConfigList = [
            {
              companyId: "",
              companyName: "",
              configId: "",
              openFlag: "0",
              pushConfig: "2",
              pushRule: ""
            }
          ]
        }
      } catch (e) {
        console.error(e)
      }
    },

    async submitOn() {
      let loading = null
      try {
        await this.$refs.refRegulations.handleEffect()
        loading = this.$loading({
          lock: true,
          text: "保存中",
          spinner: "el-icon-loading",
          background: "rgba(0, 0, 0, 0.7)",
        });
        let res = await apis?.saveOrUpdateConfig(this.detailForm)
        if (res.code === 200) {
          this.$message.success('修改成功')
          this.handleList()
        }

      } catch (e) {
        console.error(e)
      } finally {
        loading?.close();
      }
    },

    closeSelectedTag() {
      this.$modal.msgSuccess('取消成功')
    }
  },
};
</script>

<style scoped lang=""></style>


